<template>
	<view class="content">
		<view class="header">
			<view>
				<image :src="user.wechat_head_photo"></image>
				{{user.name}}
			</view>
			<view class="btn">我是师傅 </view>
		</view>
		<view class="tab">
			<text v-for="(item,i) in tabs" :class="{active:index==i}" @click="tab(i)">{{item}}</text>
		</view>
		<view class="item" v-for="item in list">
			<view class="box" @click="todetail(item)">
				<image :src="item.vehicle_images"></image>
				<view>
					<text class="name">{{item.car_model}}</text>
					<text>租车时间：{{item.start_time}} <br>
						{{item.end_time}}
					</text>
					<view>共计{{item.day_num}}天
						<!-- <text>￥256.38</text> -->
					</view>
				</view>
			</view>
			<button v-if="item.status==1" @click="end(item.id)">接单</button>
			<button v-if="item.status==2" @click="end(item.id)">行程结束</button>
			<button v-if="item.status==3" style="width: 240rpx;">行程已结束</button>
		</view>
	</view>
</template>

<script>
	import {
		login,
		order_list,
		end_trip
	} from '../../js/api.js'
	export default {
		data() {
			return {
				list: [],
				index: 0,
				tabs: ['行程未开始', '行程已经结束'],
				user: {}
			}
		},
		onLoad() {
			this.user = window.USER;
			login()
			this.getlist(1)
		},
		methods: {
			tab(i) {
				this.index = i;
				if (i == 0) {
					this.getlist(1)
				} else {
					this.getlist(3)
				}
			},
			async getlist(status) {
				const data = await order_list(status);
				this.list = data;
			},
			todetail(item) {
				uni.navigateTo({
					url: '../oderdetail/index?id=' + item.id
				})
			},
			async end(id) {
				const data =await end_trip(id);
				uni.showModal({
					content: data.msg
				})
				this.getlist(1)
			}
		}
	}
</script>

<style>
	.content {
		background: #f3f3f3;

	}

	.header {
		background: #fff;
		padding: 30rpx 0 30rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.header view {
		display: flex;
		align-items: center;
	}

	.header image {
		width: 124.8rpx;
		height: 124.8rpx;
		border-radius: 50%;
		margin-right: 15rpx;
	}

	.btn {
		width: 120rpx;
		height: 80rpx;
		line-height: 80rpx;
		padding-left: 40rpx;
		color: #fff;
		background: linear-gradient(90deg, #FDB139 0%, #FB6A17 100%);
		border-radius: 40rpx 0 0rpx 40rpx;
	}

	.tab {
		display: flex;
		justify-content: space-between;
		background: #fff;
		border-bottom: 1px solid #dcdcdc;
		padding-left:100rpx;
		padding-right:100rpx;
		margin-top: 24rpx;
	}

	.tab text {
		padding: 30rpx 0;
	}

	.tab text.active {
		border-bottom: 3px solid #FC912A;
	}

	.item {
		position: relative;
		background: #fff;
		padding-bottom: 114rpx;
		margin-bottom: 30rpx;
	}

	.box {
		display: flex;
		justify-content: space-between;
		padding: 24rpx;
		border-bottom: 1px solid #dcdcdc;
	}

	.box image {
		width: 236rpx;
		height: 182rpx;
		box-shadow: 0px 0px 9rpx 0px rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
	}

	.box text {
		display: block;
	}

	.box .name {
		font-weight: bold;
	}

	.box text:nth-of-type(2) {
		margin-top: 13rpx;
		margin-bottom: 54rpx;
		color: #999999;
	}

	.box view view {
		display: flex;
		color: #999999;
	}

	.box view view text {
		color: #FC912A;
	}

	.item button {
		position: absolute;
		right: 30rpx;
		margin-top: 20rpx;
		width: 182rpx;
		height: 64rpx;
		line-height: 64rpx;
		text-align: center;
		background: #FC912A;
		border-radius: 10rpx;
		color: #fff;
	}
</style>
